<!DOCTYPE html>
<html lang='zh-CN'>
     <head>
        <meta charset="utf-8">
    <title>新三国ol_html版本_背包</title>
    <script src="jquery-3.6.0.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
     </head>
<body>
    <p class="h1" id="puser"></p>
<p>当前体力值：100</p>
<p>金币：100</p>
<p>银两：100</p>

<hr/>
<h1>功能</h1>

<table class="table">

    <tbody id="tbd">
        <tr>
            <td scope="row">物品</td>
            <td>数量</td>
            <td>操作</td>
        </tr>
        
       
        
    </tbody>
</table>
<p><button onclick="history.back()" >返回</button></p>

</body>
<script>
    function getGoodsNameByGid(gid){

        var gname = "";
        switch(parseInt(gid)){
            case 1:
            gname = "招兵令";
            break;
            case 2:
            gname = "招贤令";
            break;
            case 3:
            gname = "将军令";
            break;
            case 4:
            gname = "大将军令";
            break;
            case 5:
            gname = "体力丹";
            break;
            case 6:
            gname = "副将经验书";
            break;
            case 7:
            gname = "原矿";
            break;
            case 8:
            gname = "精矿";
            break;
            case 9:
            gname = "珍矿";
            break;
            case 10:
            gname = "1级技能书";
            break;
            case 11:
            gname = "2级技能书";
            break;
            case 12:
            gname = "3级技能书";
            break;
            case 13:
            gname = "4级技能书";
            break;
            case 14:
            gname = "5级技能书";
            break; 
            case 15:
            gname = "小银袋";
            break;      

        }
     return gname;
     
    }
    
    var goodsList = [];
    var url="https://2020cn.cn/hxsg/api/user_mgr";

    $(document).ready(function () {
        if($.cookie("user_id") == null){
            alert("请登录!");
            window.location.href="index.html";
            return;
        }
  
        $('#puser')[0].innerHTML = "欢迎:"+$.cookie('account');
        var user_id = $.cookie('user_id');
        $.post(
            url,
            {
                "action":"getUserGoodsList",
                 
                "user_id"  :user_id
            },
            function (res) {
                  console.log(res);
                  const resobj = JSON.parse(res);
                    console.log(resobj.data)
                   
                   
                    for(ele of resobj.data){
                        
                        if((parseInt(ele.goods_id) !== 16 && parseInt(ele.goods_id) !== 17)){
                            var node = $("<tr><td scope='row'>"+getGoodsNameByGid(ele.goods_id)+"</td><td>"+ele.counts+"</td><td><button disabled>使用</button></td> </tr>");

                            $("#tbd").after(node);
                        }
                       
                    }
                  
                /*
                 if(resobj.code == "200"){
                   
                 
                  }else if (resobj.code == "201"){
                    //console.log(resobj.msg);
                   
                  }
               */
            }
        );
        
    });
    function GetQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
        var context = "";
        if (r != null)
            context = decodeURIComponent(r[2]);
        reg = null;
        r = null;
        return context == null || context == "" || context == "undefined" ? "" : context;
    }
   
    
     function click_back(){
            window.location.href="home.html";
      
    }
   


</script>
</html>